using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using ZombieHigh2.Controller;
using ZombieHigh2.Interfaces;
using ZombieHigh2.Audio;
using ZombieHigh2.AI;
using QuadAnimation.Animation;

namespace ZombieHigh2.Actor
{
    public class Monster : BaseActor
    {
        protected BaseState lastState;

        public Monster(ActionEvents actions, AudioSystem audio, AnimatedObject animatedObject)
            : base(actions, audio, animatedObject)
        {
        }

        public override void Update(GameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            ControllerData controlData;
            BaseState currentState;

            base.Update(gameTime);

            controlData = InputController.GetControllerData();
            controlData.LAnalog *= 0.5f;
            Velocity.X = controlData.LAnalog.X;
            Velocity.Z = controlData.LAnalog.Y;

            currentState = ((BaseAIController)InputController).GetCurrentState();

            /* Idle State */
            if (currentState is IdleState)
            {
                SetCurrentState(PlayerState.PSTATE_IDLE);
                IdleTime -= elapsedTime;

                //if (lastState is IdleState)
                //{
                //    
                //}
                //else
                //{
                //    lastState = currentState;
                //    IdleTime = 3f;
                //}
            }
            /* Walk State */
            else if (currentState is WalkState)
            {
                SetCurrentState(PlayerState.PSTATE_WALKING);
                //if (!(lastState is WalkState))
                //{
                //    SetAnimationCycle("Walk");
                //    lastState = currentState;
                //}

                if (Velocity.X > 0)
                    Direction = PlayerDirection.PDIR_RIGHT;
                else if (Velocity.X < 0)
                    Direction = PlayerDirection.PDIR_LEFT;
            }
            /* Attacking State */
            else if (currentState is MeleeState)
            {
                SetCurrentState(PlayerState.PSTATE_ATTACKING);
                //System.Console.WriteLine("Attack");
                //if (!(lastState is MeleeState))
                //{
                //    SetAnimationCycle("Attack");
                //    lastState = currentState;
                //}
            }
            /* Stun State */
            else if (currentState is StunState)
            {
                //if (CurrentPlayerState != PlayerState.PSTATE_STUNNED)
                SetCurrentState(PlayerState.PSTATE_STUNNED);

                StunTime -= elapsedTime;
                //System.Console.WriteLine("Stun");
            }
            /* Death State */
            else if (currentState is DeathState)
            {
                SetCurrentState(PlayerState.PSTATE_DEAD);
            }




        }

        public override void Info_Damage(BaseActor who, int amount)
        {
            Health -= amount;

            if (Health < 0)
                Health = 0;

            if (Health == 0)
                IsDead = true;
        }


    }

}
